package engine;

import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ResourceManager {

	private static final String pixmaps = "./data/sprites/";

	public static Image loadSprite(String filename) {
		BufferedImage image = null;
		try {
			image = ImageIO.read(new File(pixmaps + filename));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return flipImage(image);
	}

	private static Image flipImage(BufferedImage image) {
		AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
		tx.translate(0, -image.getHeight(null));
		AffineTransformOp op = new AffineTransformOp(tx,
				AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
		return op.filter(image, null);
	}

}
